<template>
	<view>
		<view class="mt-5" v-if="u_loadmore">
			<u-loadmore status="loading" icon-type="circle" />
		</view>
		<view v-else>
			<view class="rounded-20 m-2 pl-3  bg-white" >
				<view class="d-flex j-sb pr-2 py-3">
					<view class="">限购数量</view>
					<view class="d-flex j-center a-center">
						<input type="digit" v-model="limit_number" :placeholder="buylimit_info.limit_number" class="text-right" placeholder-class="d-flex j-end" @click="buylimit_input" />
					</view>
				</view>		
			</view>
			<view class="rounded-20 m-2 pl-3  bg-white" >
				<view class="d-flex j-sb pr-2 py-3">
					<view class="">开始时间</view>
					<view class="d-flex j-center a-center">
						<view class="text-right text-muted" @click="initiate">{{initiate_time==!'undefined'?'选择开始的时间':initiate_time}}</view>
					</view>
				</view>		
			</view>
			<view class="rounded-20 m-2 pl-3  bg-white" >
				<view class="d-flex j-sb pr-2 py-3">
					<view class="">结束时间</view>
					<view class="d-flex j-center a-center">
						<view class="text-right text-muted" @click="conclude">{{conclude_time==!'undefined'?'选择开始的时间':conclude_time}}</view>
					</view>
				</view>		
			</view>
			
			<view class="rounded-20 m-2 pl-3  bg-white" >
				<view class="d-flex j-sb pr-2 py-3">
					<view class="">是否设置为限购</view>
					<view class="d-flex j-center a-center">
						<u-switch v-model="buylimit_info.is_limit" @change="purchase" size="39"></u-switch>
					</view>
				</view>		
			</view>
			<view class="bg-white py-2 w-100 position-fixed bottom-0 btn">
				<button type="warn" @click="preserve">保存</button>
			</view>
		</view>
		
		<!-- 开始 -->
		<u-picker v-model="initiate_show" mode="time" @confirm="initiate_confirm"></u-picker>
		<!-- 结束 -->
		<u-picker v-model="conclude_show" mode="time" @confirm="conclude_confirm"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				buylimit_info:"", // 限购数量详情
				initiate_show:false,// 开始 开关
				initiate_time:"", // 开始时间
				conclude_show:false, // 结束开关
				conclude_time:"", // 结束时间
				goods_id:0, // 商品ID
				limit_number:'', // 限购数量
				limit_show:"yes", // 限购开关
				u_loadmore:true, // 加载中
			}
		},
		methods: {
			// 限购数量
			buylimit_input(e){
				this.limit_number=e.detail.value
			},
			// 限购开关
			purchase(e){
				console.log(e)
				if(e==true){
					this.limit_show="yes"
					console.log(this.limit_show)
				}else{
					this.limit_show="no"
					console.log(this.limit_show)
				}
			},
			// 开始时间
			initiate(){
				this.initiate_show=true
			},
			// 结束时间
			conclude(){
				this.conclude_show=true
			},
			// 开始
			initiate_confirm(e){
				this.initiate_time=`${e.year}-${e.month}-${e.day}`;
			},
			// 结束
			conclude_confirm(e){
				this.conclude_time=`${e.year}-${e.month}-${e.day}`;
			},
			// 保存
			preserve(){
				this.$H.post("admin/merchant/goods/purchaselimit/add",{
					goods_id:this.goods_id,
					is_limit:this.limit_show,
					limit_number:this.limit_number,
					start_date:this.initiate_time,
					end_date:this.conclude_time,
					}).then(res=>{
					uni.navigateBack({
						delta:1
					})
					
					var globalData = getApp().globalData.restriction; //获取全局变量
					getApp().globalData.restriction= '限购'; //修改全局变量
				})
			}
		},
		onLoad(e) {
			this.goods_id=e.goods_id
			this.$H.post("admin/merchant/goods/special/info",{goods_id:e.goods_id}).then(res=>{
				console.log(res)
				this.buylimit_info=res.data.buylimit_info 
				this.initiate_time=this.buylimit_info.xiangou_start_date.substring(0,10);
				this.conclude_time=this.buylimit_info.xiangou_end_date.substring(0,10);
				this.u_loadmore=false 
			})
		}
	}
</script>

<style>
	.btn /deep/ button{
		width: 85%;
		border-radius: 50upx;
		background: linear-gradient(to right,#F31E3E,#FB4F37);
	}
</style>
